/**
 * Created by kevin on 16/3/6.
 */
function uploadFileById(thiss,cllback){
    $("body").append("<iframe id='UploadDocument' name='ifm'  style='display:none;' ></iframe>");

    var file = $(thiss);

    var win2 = document.getElementById('UploadDocument').contentWindow;
    if(win2.document.body!='undefiend'&&win2.document.body!=null){
        win2.document.body.innerText="";
    }
    var timer;
    var fileinfo = "";
    $("#"+thiss.id+"Form").submit();
    timer = setInterval(dodo,500);
    function dodo(){
        var win = document.getElementById('UploadDocument').contentWindow;
        if(win.document.body=='undefiend'||win.document.body==null){
            return;
        }
        var info = win.document.body.innerText;
        fileinfo = info;
        if(fileinfo.length>0){
            clearInterval(timer);
            $("#UploadDocument").remove();
            var rs = eval("["+fileinfo+"]")[0].result;
            cllback(rs);
            file.val("");
        }
    }
}

Array.prototype.indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

function requestServlet(servletUrl,parameter,success,failure){
    $.ajax({
        url:'/suite/plugins/servlet/'+servletUrl,
        data:parameter,
        type:'post',
        async: false,
        success:function(rs) {
            if(rs.code==0){
                success(rs.result);
            }else{
                console.log(servletUrl+": "+rs);
                failure(rs.msg);
            }
        },
        error : function() {
            console.log(servletUrl+": background error");
            failure("background error");
        }
    });
}


(function($) {
    $.fn.videoPause = function() {
        $('video').each(function(){
            this.pause();
        });
    };
})(jQuery);